#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-6-25 下午8:49
# @Author  : Tom
# @Site    : 
# @File    : specs.py
# @Software: PyCharm
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SKU, SPUSpecification, SpecificationOption
from meiduo_admin.serilizers import SpecsSerilizer, SpecsOptionSerilizer
from meiduo_admin.utils import PageNumber_User


# sku的增删查改
class SpecsView(ModelViewSet):
    # 添加序列化器和查询集
    serializer_class = SpecsSerilizer
    queryset = SPUSpecification.objects.all()
    # 指定分页类
    pagination_class = PageNumber_User
    permission_classes = [IsAdminUser, ]


# 规格选项的增删查改
class SpecOptionView(ModelViewSet):
    # 添加序列化器和查询集
    serializer_class = SpecsOptionSerilizer
    queryset = SpecificationOption.objects.all()
    # 指定分页类
    pagination_class = PageNumber_User
    permission_classes = [IsAdminUser, ]

    def specsView(self, request):
        specs = SPUSpecification.objects.all()
        ser = SpecsSerilizer(specs, many=True)
        return Response(ser.data)
